package com.hhb.web.controller;

import com.hhb.model.User;
import com.hhb.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

@Controller
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public String list(Model model){
        List<User> users = userService.findAll();
        System.out.println(users);
        model.addAttribute("users",users);
        System.out.println("springMVC表现出，查找所有用户！");
        return "list";
    }

    @RequestMapping(value = "/save" ,method = RequestMethod.POST)
    public String save(User user, Model model){
        userService.save(user);
        model.addAttribute("user",user);
        System.out.println(user);
        return "list";
    }
}
